<!DOCTYPE html>
<html>
<head>
  <title>Test - OOP</title>
  <link rel="stylesheet" href="QUnit.css" type="text/css" />
  <script type="text/javascript" src="QUnit.js"></script>
  <script type="text/javascript" src="QUnitExt.js"></script>
</head>
<body>
  <h1 id="qunit-header">Test Results</h1>
  <h2 id="qunit-banner"></h2>
  <h2 id="qunit-userAgent"></h2>
  <ol id="qunit-tests"></ol>
  <br />
  <textarea id="qunit-log" rows="10" cols="100"></textarea>
</body>
<script type="text/javascript" src="..\..\bin\Debug\mscorlib.debug.js"></script>
<script type="text/javascript" src="TestOOP.js"></script>
<script type="text/javascript">
module('OOP');
test('isClass', function() {
  QUnit.equal(Type.isClass(Test.Cat), true, 'Expected Cat to be a class');
  QUnit.equal(Type.isClass(Test.IPet), false, 'Did not expect IPet to be a class');
  QUnit.equal(Type.isClass(Test.More.Comic), true, 'Expectd Comic to be a class');
});

test('isInteface', function() {
  QUnit.equal(Type.isInterface(Test.Cat), false, 'Did not expect Cat to be an interface');
  QUnit.equal(Type.isInterface(Test.IPet), true, 'Expected IPet to be an interface');
  QUnit.equal(Type.isInterface(Test.More.Comic), false, 'Did not expect Comic to be an interface');
});

test('isAssignableFrom', function() {
  QUnit.equal(Test.Animal.isAssignableFrom(Test.Cat), true, 'Cat should be assignable to an Animal');
  QUnit.equal(Test.IMammal.isAssignableFrom(Test.Cat), true, 'Cat should be assignable to an IMammal');
  QUnit.equal(Test.IMammal.isAssignableFrom(Test.Garfield), true, 'Garfield should be assignable to an IMammal');
  QUnit.equal(Test.IPet.isAssignableFrom(Test.Cat), false, 'Cat should not be assignable to an IPet');
  QUnit.equal(Object.isAssignableFrom(Test.Cat), true, 'Cat should be assignable to an Object');
});

test('isInstance', function() {
  var c = new Test.Cat();
  var g = new Test.Garfield();

  QUnit.equal(Test.Animal.isInstanceOfType(c), true, 'Cat instance should be an Animal instance');
  QUnit.equal(Test.IMammal.isInstanceOfType(c), true, 'Cat instance should be an IMammal instance');
  QUnit.equal(Test.IMammal.isInstanceOfType(g), true, 'Garfield instance should be an IMammal instance');
  QUnit.equal(ss.StringBuilder.isInstanceOfType(c), false, 'Cat instance should not be a StringBuilder instance');
  QUnit.equal(Test.IPet.isInstanceOfType(c), false, 'Cat instance should not be an IPet instance');
  QUnit.equal(Object.isInstanceOfType(c), true, 'Cat instance should not be an Object instance');
});

test('get_baseType', function() {
  QUnit.equal(Test.Cat.get_baseType().get_fullName(), 'Test.Animal', 'Cat\'s base type should be Test.Animal');
  QUnit.equal(Test.Animal.get_baseType().get_fullName(), 'Object', 'Animal\'s base type should be Object');
  QUnit.equal(Object.get_baseType(), null, 'Object\'s base type should be null');
});

test('canCast and safeCast', function() {
  var g = new Test.Garfield();

  QUnit.equal(Type.canCast(g, Test.IPet), true, 'Garfield instance should be castable to Test.IPet');
  QUnit.equal(Type.canCast(g, Test.Animal), true, 'Garfield instance should be castable to Test.Animal');
  QUnit.equal(Type.canCast(g, ss.IDisposable), false, 'Garfield instance should not be castable to IDisposable');
  QUnit.equal(Type.safeCast(g, Test.IPet), g, 'Garfield instance should be castable to Test.IPet');
  QUnit.equal(Type.safeCast(g, Test.Animal), g, 'Garfield instance should be castable to Test.Animal');
  QUnit.equal(Type.safeCast(g, ss.IDisposable), null, 'Garfield instance should not be castable to IDisposable');
});

test('initializeBase', function() {
  var c = new Test.Cat();
  QUnit.equal(c.get_species(), 'Cat', 'Cat is of cat species');
});

test('callBaseMethod', function() {
  var g = new Test.Garfield();
  QUnit.equal(g.speak(), 'meow\r\nI am fat, lazy, and cynical, but still, a favorite cat...', 'Garfield meows and says something cute');
});

test('getInstanceType', function() {
  var g = new Test.Garfield();
  QUnit.equal(Type.getInstanceType(g), Test.Garfield, "Expected Test.Garfield instance.");

  var c = new Test.More.Comic();
  QUnit.equal(Type.getInstanceType(c), Test.More.Comic, "Expected Test.More.Comic instance.");
});

test('typeNames', function() {
  var g = new Test.Garfield();
  QUnit.equal(Type.getInstanceType(g).get_name(), 'Garfield', "Expected 'Garfield' for type name.");
  QUnit.equal(Type.getInstanceType(g).get_fullName(), 'Test.Garfield', "Expected 'Test.Garfield' for type name.");

  var c = new Test.More.Comic();
  QUnit.equal(Type.getInstanceType(c).get_name(), 'Comic', "Expected 'Comic' for type name.");
  QUnit.equal(Type.getInstanceType(c).get_fullName(), 'Test.More.Comic', "Expected 'Test.More.Comic' for type name.");
});

test('getType', function() {
  var t1 = Type.getType('String');
  var t2 = Type.getType('ss.StringBuilder');
  var t3 = Type.getType('Test.Garfield');
  var t4 = Type.getType('Test.More.Comic');
  var t5 = Type.getType('Test.Foo');

  QUnit.equal(t1, String, "Expected String type.");
  QUnit.equal(t2, ss.StringBuilder, "Expected StringBuilder type.");
  QUnit.equal(t3, Test.Garfield, "Expected Garfield type.");
  QUnit.equal(t4, Test.More.Comic, "Expected Comic type.");
  QUnit.equal(t5, null, "Expected null type.");
});
</script>
</html>
